package sr.myserver.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sr.myserver.commons.Result;
import sr.myserver.entity.SysButtons;
import sr.myserver.mapper.SysButtonsMapper;
import sr.myserver.mapper.SysMenusMapper;
import sr.myserver.mapper.SysRoleMenuMapper;
import sr.myserver.service.SysButtonsService;
import sr.myserver.vo.SelectData;
import sr.myserver.vo.common.Basic;
import sr.myserver.vo.common.PageRequest;
import sr.myserver.vo.common.PageResponse;

import java.io.Serializable;

/**
 * 按钮信息
 *
 * @author sirui
 **/
@Service
public class SysButtonsServiceImpl implements SysButtonsService {

    @Autowired
    SysButtonsMapper sysButtonsMapper;
    @Autowired
    SysMenusMapper sysMenusMapper;
    @Autowired
    SysRoleMenuMapper sysRoleMenuMapper;

    /**
     * 查询一条数据（主键）
     *
     * @param id 主键
     * @return
     */
    @Override
    public SysButtons get(Serializable id) {
        return sysButtonsMapper.selectById(id);
    }

    /**
     * 增加一条数据
     *
     * @param entity
     * @return
     */
    @Override
    public Basic.Response add(SysButtons entity) {
        sysButtonsMapper.insert(entity);
        return Result.ok();
    }

    /**
     * 修改一条数据
     *
     * @param entity
     * @return
     */
    @Override
    public Basic.Response update(SysButtons entity) {
        sysButtonsMapper.updateById(entity);
        return Result.ok();
    }

    /**
     * 删除一条数据
     *
     * @param id 主键
     * @return
     */
    @Override
    public Basic.Response deleteById(Serializable id) {
        sysButtonsMapper.deleteById(id);
        return Result.ok();
    }

    /**
     * 列表数据查询
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse<SysButtons> queryTables(PageRequest request) {
        IPage<SysButtons> data = sysButtonsMapper.queryTables(request.getPage(), request.getQueryData());
        return new PageResponse(data.getCurrent(), data.getSize(), data.getTotal(), data.getRecords());
    }

    /**
     * 分页下拉查询
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse<SelectData> querySelect(PageRequest request) {
        IPage<SelectData> data = sysButtonsMapper.querySelect(request.getPage(), request.getQueryData());
        return new PageResponse(data.getCurrent(), data.getSize(), data.getTotal(), data.getRecords());
    }
}

